package com.taiji.dicom4cloud.common.core.utils;

import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * @Description
 * @Author fanxl
 * @Date 2021/5/21
 **/
public class KeyNumberUtils {
    private static String DATE_FORMAT = "MMddHHmmss";

    private static final SecureRandom RANDOM = new SecureRandom();

    /**
     * 生成Id
     *
     * @param priFix
     * @return
     */
    public static String getKeyNumber(String priFix) {
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
        return priFix + sdf.format(getDate()) + StringUtils.leftPad(Integer.toString(RANDOM.nextInt((int) Math.round(Math.pow(10, 3)))), 3,
                '0');
    }
    /**
     * 获取当前时间字符串
     */
    public static Date getDate() {
        LocalDateTime localDateTime = LocalDateTime.now();
        return Date.from(localDateTime.atZone(ZoneId.of(ZoneId.SHORT_IDS.get("CTT"))).toInstant());
    }


}
